package com.zhangjm.controller;

import com.zhangjm.User;
import com.zhangjm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user/")
public class UserController {

    @Autowired
    private UserService userService;

//    @RequestMapping("getUsernameById")
//    public String getUsernameById(@RequestParam("id") Integer id){
//        return userService.getUsernameById(id);
//    }
    /**
     * 根据用户Id，查询用户名称
     * @param id
     * @return
     */
    @GetMapping("getUsernameById")
    public String getUsernameById(@RequestParam("id") Integer id){
        return userService.getById(id).getUsername();
    }


    @RequestMapping("getById")
    public User getUserById(@RequestParam("id") Integer id){
        return userService.getById(id);
    }
}